package com.cdxy.model.dto.base.redis.util;

import com.cdxy.enums.redis.IRedisCacheGroup;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @Author: tangy
 * @Date: 2020/2/23 14:37
 */
@Component
@Slf4j
public class KeyGeneratorUtil {

    @Value("${spring.application.name:gda}")
    private String applicationName;


    public String generateCacheKey(IRedisCacheGroup group) {
        if (group == null) {
            return null;
        }
        return applicationName +
                ":" +
                "cache" +
                ":" +
                group.getGroup();
    }

    public String generateCacheKey(IRedisCacheGroup group, String value) {
        if (group == null || StringUtils.isBlank(value)) {
            return null;
        }
        return applicationName +
                ":" +
                "cache" +
                ":" +
                group.getGroup() +
                ":" +
                value;
    }
}
